﻿ --|--------------------------------------------------------------------------------
--| [GetGameStatistic] - Insert Procedure Script for GPSPoint
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[GetGameStatistic]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[GetGameStatistic]
GO

CREATE PROCEDURE [dbo].[GetGameStatistic]
(
	@GameName nvarchar(50)
)
AS
	SET NOCOUNT ON
	
	SELECT [EntityName], 
		Max(Speed) as Maximum, 
		AVG(Speed) as Average,
		COUNT(*) as Points,
		Max(Time) as LastUpdateTime
	FROM [GPSPoint]
	WHERE [GameName] = @GameName
	GROUP BY [EntityName]
	ORDER BY Max(Speed)
	
GO
